﻿Imports FSUIPC
Module Throttle_Pos

#Region "FSUIPC Addresses Screen 3 - Engine Information."
    ' Throttle Positions.
    Dim Eng1_Throttle_Pos As Offset(Of Short) = New FSUIPC.Offset(Of Short)("Screen3", &H88C)
    Dim Eng2_Throttle_Pos As Offset(Of Short) = New FSUIPC.Offset(Of Short)("Screen3", &H924)
    Dim Eng3_Throttle_Pos As Offset(Of Short) = New FSUIPC.Offset(Of Short)("Screen3", &H9BC)
    Dim Eng4_Throttle_Pos As Offset(Of Short) = New FSUIPC.Offset(Of Short)("Screen3", &HA54)
#End Region

#Region "Screem 3 - Engine Information"
    Public Sub Display_Screen()
        Dim img As New System.Drawing.Bitmap(160, 43)
        Dim screen As Drawing.Graphics = Graphics.FromImage(img)
        Try
            FSUIPC.FSUIPCConnection.Process("Screen3")

            ' Format Percentages.
            Dim Eng1_Throttle_Position_Calc As Double = (Eng1_Throttle_Pos.Value * 100 / 16384)
            Dim Eng2_Throttle_Position_Calc As Double = (Eng2_Throttle_Pos.Value * 100 / 16384)
            Dim Eng3_Throttle_Position_Calc As Double = (Eng3_Throttle_Pos.Value * 100 / 16384)
            Dim Eng4_Throttle_Position_Calc As Double = (Eng4_Throttle_Pos.Value * 100 / 16384)

            ' Engines 1 & 2.
            screen.DrawString("Eng 1 Thr:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(1, 2, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(68, 2, 160, 43))

            screen.DrawString("Eng 2 Thr:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(1, 14, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(68, 14, 160, 43))

            ' Engines 3 & 4.
            screen.DrawString("Eng 3 Thr:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(81, 2, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(148, 2, 160, 43))

            screen.DrawString("Eng 4 Thr:", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(81, 14, 160, 43))
            screen.DrawString("%", New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(148, 14, 160, 43))

            screen.DrawLine(Pens.White, 0, 0, 159, 0)
            screen.DrawLine(Pens.White, 0, 37, 159, 37)
            screen.DrawLine(Pens.White, 79, 0, 79, 37)
            screen.DrawLine(Pens.White, 0, 0, 0, 37)
            screen.DrawLine(Pens.White, 159, 0, 159, 37)

            ' Display Data.
            ' Engines 1 & 2.
            screen.DrawString(FormatNumber(Eng1_Throttle_Position_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(45, 2, 160, 43))
            screen.DrawString(FormatNumber(Eng2_Throttle_Position_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(45, 14, 160, 43))
            ' Engines 3 & 4.
            screen.DrawString(FormatNumber(Eng3_Throttle_Position_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(125, 2, 160, 43))
            screen.DrawString(FormatNumber(Eng4_Throttle_Position_Calc, 1), New Font(FontType, FontSize, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, New RectangleF(125, 14, 160, 43))

        Catch exFSUIPC As FSUIPCException
            MainTimer.Stop()
            CheckTimer.Start()
        Finally
            G15FS9_Main.lcd.DrawLCD(img)
            G15FS9_Main.lcd.UpdateLCD()
        End Try
    End Sub
#End Region

End Module
